package com.qfedu.meidijiaju.controller;

import com.qfedu.meidijiaju.entity.Card;
import com.qfedu.meidijiaju.service.CardService;
import com.qfedu.meidijiaju.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "卡包模块接口")
@RestController
public class CardController {
    @Autowired
    private CardService cardService;

    /**
     * 查询用户卡包，根据用户uid和卡包类型type
     * @param card
     * @return
     */
    @ApiOperation("查询用户卡包，根据用户uid和卡包类型type")
    @RequestMapping(value = "/card/queryCard",method = RequestMethod.GET)
    public ResponseData<List<Card>> queryCard(Card card) {
        ResponseData<List<Card>> responseData = new ResponseData<>();
        List<Card> result = cardService.queryCard(card);

        if (result != null) {
            responseData.setCode(0);
            responseData.setData(result);
        }

        return responseData;

    }

    @ApiOperation("添加卡包，根据用户uid和卡包类型type 添加")
    @RequestMapping(value = "/card/addCard",method = RequestMethod.GET)
    public ResponseData<String> addCard(Card card) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = cardService.addCard(card);

        if (result) {
            responseData.setCode(0);
            responseData.setMsg("添加成功");
        }

        return responseData;
    }

    @ApiOperation("使用卡包接口，根据卡包类型type，用户uid，卡包名称cardName")
    @RequestMapping(value = "/card/deleteCard",method = RequestMethod.GET)
    public ResponseData<String> deleteCard(Card card) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = cardService.deleteCard(card);

        if (result) {
            responseData.setCode(0);
            responseData.setMsg("删除（使用）成功");
        }

        return responseData;
    }
}
